package internal

import (
	"GameServer/Common/data"
	"fmt"
)

// 章节
type TempPage struct {
	// 所有英雄
	MTempHero map[uint64]*data.Hero
	LTempHero []*data.Hero
	// 英雄的所有装备
	MTempGood map[uint64]*data.Good
	LTempGood []*data.Good
}

func NewTempPage() *TempPage {
	return &TempPage{
		MTempHero: make(map[uint64]*data.Hero),
		LTempHero: make([]*data.Hero, 0),
		MTempGood: make(map[uint64]*data.Good),
		LTempGood: make([]*data.Good, 0),
	}
}

// 加载模块，初始化数据
func (t *TempPage) Init() {
	fmt.Println("初始化所有英雄")
	lherosTpl, ok := data.GetAllDatas("Heros")
	if !ok {
		// 	err = errors.NewErrcode(data.Errcode.ConfigNotFound, "没有找到角色表,Heros")
		fmt.Println("没有角色配置表")
		return
	}

	for _, item := range lherosTpl {
		hero := item.(data.Hero)
		t.LTempHero = append(t.LTempHero, &hero)
		t.MTempHero[hero.Id] = &hero
	}

	lgoodsTpl, ok := data.GetAllDatas("Goods")
	if !ok {
		// err = errors.NewErrcode(data.Errcode.ConfigNotFound, "没有神秘商店刷新时间配置")
		fmt.Println("没有物品配置表")
		return
	}

	for _, item := range lgoodsTpl {
		good := item.(data.Good)
		_, ok := t.MTempHero[good.Owner]
		if ok {
			t.LTempGood = append(t.LTempGood, &good)
			t.MTempGood[good.Id] = &good
		}
	}
}

func (t *TempPage) Run(closeSig chan bool) {

}

func (t *TempPage) Destroy() {

}
